﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DAL_Contacts
/// </summary>
public class DAL_Contacts :clsConnection
{
    DataTable dt = new DataTable();
    public Boolean DAL_Contact_Insert(DTO_Contact contact)
    {
        try
        {
            string sql = "INSERT INTO Contact(name, title, phone, email, contents, status ) VALUES(@name, @title, @phone, @email, @contents, @status)";
            AddParameter(new SqlParameter("@name", contact.Name));
            AddParameter(new SqlParameter("@title", contact.Title));
            AddParameter(new SqlParameter("@phone", contact.Phone));
            AddParameter(new SqlParameter("@email", contact.Email));
            AddParameter(new SqlParameter("@contents", contact.Content));
            AddParameter(new SqlParameter("@status", contact.Status));
            if (ExcuteNonQuery(sql))
            {
                return true;
            }
            else
                return false;
        }
        catch
        {
            return false;
        }
    }
    public DataTable DAL_Contact_getById(int status, int lh, int id)
    {
        dt.Rows.Clear();
        dt.Columns.Clear();
        try
        {
            string sql = string.Format("SELECT id, name, phone, email, title, contents, {0} AS LH FROM Contact WHERE status = {1} AND id = {2}", lh, status, id);
            dt = ExcuteQuery(sql);
        }
        catch
        {
        }
        return dt;
    }
    public Boolean DAL_Contact_Update(DTO_Contact dtoC)
    {
        try
        {
            string sql = "UPDATE Contact SET status = @status WHERE id = @id";
            AddParameter(new SqlParameter("@id", dtoC.ID));
            AddParameter(new SqlParameter("@status", dtoC.Status));
            if (ExcuteNonQuery(sql))
            {
                return true;
            }
            else
                return false;
        }
        catch
        {
            return false;
        }
    }
    public DataTable DAL_Contact_getData(int status, int lh)
    {
        dt.Rows.Clear();
        dt.Columns.Clear();
        try
        {
            string sql = string.Format("SELECT id, name, phone, email, title, contents, {0} AS LH FROM Contact WHERE status = {1}", lh, status);
            dt = ExcuteQuery(sql);
        }
        catch
        {
        }
        return dt;
    }
}